package com.fairytask.ui.mainUnit
{
	import com.fairytask.engine.components.ToolTips;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.managers.TipsManage;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	/**
	 * 
	 * 获得幸运符
	 * @author zhut
	 */
	public class LuckyRefUI extends FrameUI
	{
		public static var _self:LuckyRefUI;
		public var LuckyBG1:MovieClip;		//背景
		public var LuckyBG2:MovieClip;
		public var LuckyBG3:MovieClip;
		public var BuyBtn1:Button;			// 不同的按钮
		public var BuyBtn2:Button;
		public var BuyBtn3:Button;
		public var BuyBtn4:Button;
		public var BuyBtn5:Button;
		public var clip1:Clip;			//添加的的clip
		public var clip2:Clip;
		public var clip3:Clip;
		public var clip4:Clip;
		public var clip5:Clip;
		public var numLab1:Label;		//显示的数量
		public var numLab2:Label;
		public var numLab3:Label;
		public var numLab4:Label;
		public var numLab5:Label;
		private var _list:Array=[];
		private var _pos:int;
		
		private var _num:Array = [0,0,0,0,0];		//用于存放每个幸运符的数量
		private var _luckyStr:Array	=	[];
		public static function getInstance():LuckyRefUI
		{
			if(_self==null)
			{
				_self=new LuckyRefUI();
			}
			return _self;
		}
		public function LuckyRefUI()
		{
			initEvent();
		}
		//监听事件
		private function initEvent():void
		{
			//给图片和按钮添加点击事件
			BuyBtn1.addEventListener(MouseEvent.CLICK,onBase);
			BuyBtn2.addEventListener(MouseEvent.CLICK,onMid);
			BuyBtn3.addEventListener(MouseEvent.CLICK,onHigh);
			BuyBtn4.addEventListener(MouseEvent.CLICK,onHigh1);
			BuyBtn5.addEventListener(MouseEvent.CLICK,onHigh2);
			clip1.addEventListener(MouseEvent.CLICK,onaddBase);
			clip2.addEventListener(MouseEvent.CLICK,onaddMid);
			clip3.addEventListener(MouseEvent.CLICK,onaddHigh);
			clip4.addEventListener(MouseEvent.CLICK,onaddHigh1);
			clip5.addEventListener(MouseEvent.CLICK,onaddHigh2);
			clip1.addEventListener(MouseEvent.ROLL_OVER,onOver1);
			clip1.addEventListener(MouseEvent.ROLL_OUT,onOut1);
			clip2.addEventListener(MouseEvent.ROLL_OVER,onOver2);
			clip2.addEventListener(MouseEvent.ROLL_OUT,onOut2);
			clip3.addEventListener(MouseEvent.ROLL_OVER,onOver3);
			clip3.addEventListener(MouseEvent.ROLL_OUT,onOut3);
			clip4.addEventListener(MouseEvent.ROLL_OVER,onOver4);
			clip4.addEventListener(MouseEvent.ROLL_OUT,onOut4);
			clip5.addEventListener(MouseEvent.ROLL_OVER,onOver5);
			clip5.addEventListener(MouseEvent.ROLL_OUT,onOut5);
		}
		
		/**
		 *删除tips 
		 * @param evt
		 * 
		 */		
		private function onOut1(evt:MouseEvent):void
		{
			ToolTips.hide();
		}
		/**
		 *添加tips 
		 * @param evt
		 * 
		 */		
		private function onOver1(evt:MouseEvent):void
		{
			TipsManage.ShowItemTips(_list[0],true);
		}
		/**
		 *删除tips 
		 * @param evt
		 * 
		 */		
		private function onOut2(evt:MouseEvent):void
		{
			ToolTips.hide();
		}
		/**
		 *添加tips 
		 * @param evt
		 * 
		 */		
		private function onOver2(evt:MouseEvent):void
		{
			TipsManage.ShowItemTips(_list[2],true);
		}
		/**
		 *删除tips 
		 * @param evt
		 * 
		 */		
		private function onOut3(evt:MouseEvent):void
		{
			ToolTips.hide();
		}
		/**
		 *添加tips 
		 * @param evt
		 * 
		 */		
		private function onOver3(evt:MouseEvent):void
		{
			TipsManage.ShowItemTips(_list[4],true);
		}
		/**
		 *删除tips 
		 * @param evt
		 * 
		 */		
		private function onOut4(evt:MouseEvent):void
		{
			ToolTips.hide();
		}
		/**
		 *添加tips 
		 * @param evt
		 * 
		 */		
		private function onOver4(evt:MouseEvent):void
		{
			TipsManage.ShowItemTips(_list[6],true);
		}
		/**
		 *删除tips 
		 * @param evt
		 * 
		 */		
		private function onOut5(evt:MouseEvent):void
		{
			ToolTips.hide();
		}
		/**
		 *添加tips 
		 * @param evt
		 * 
		 */		
		private function onOver5(evt:MouseEvent):void
		{
			TipsManage.ShowItemTips(_list[8],true);
		}
		/**
		 * 给精炼ui发送数据
		 * @param e
		 * 
		 */		
		private function onaddBase(e:MouseEvent):void
		{
			if(_num[0]>0)
			{
				RefineUI.getInstance().getLuckRes(_pos,_list[0]);
			}
		}
		private function onaddMid(e:MouseEvent):void
		{
			if(_num[1]>0)
			{
				RefineUI.getInstance().getLuckRes(_pos,_list[2]);
			}
			
		}
		private function onaddHigh(e:MouseEvent):void
		{
			if(_num[2]>0)
			{
				RefineUI.getInstance().getLuckRes(_pos,_list[4]);
			}
			
		}
		
		private function onaddHigh1(e:MouseEvent):void
		{
			if(_num[3]>0)
			{
				RefineUI.getInstance().getLuckRes(_pos,_list[6]);
			}
			
		}
		
		private function onaddHigh2(e:MouseEvent):void
		{
			if(_num[4]>0)
			{
				RefineUI.getInstance().getLuckRes(_pos,_list[8]);
			}
			
		}
		private function onBase(e:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUTORMMSG_BUY_LUCKY,int(StaticIni.getIniVar(_list[0],"ConfigID")));	
		}
		private function onMid(e:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUTORMMSG_BUY_LUCKY,int(StaticIni.getIniVar(_list[2],"ConfigID")));			
		}
		private function onHigh(e:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUTORMMSG_BUY_LUCKY,int(StaticIni.getIniVar(_list[4],"ConfigID")));
		}
		private function onHigh1(e:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUTORMMSG_BUY_LUCKY,int(StaticIni.getIniVar(_list[6],"ConfigID")));
		}
		private function onHigh2(e:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUTORMMSG_BUY_LUCKY,int(StaticIni.getIniVar(_list[8],"ConfigID")));
		}
		//设置幸运符
		public function setPic(pList:Array):void
		{
			_list=pList;
			clip1.source=ResConfig.iconPath+(StaticIni.getIniVar(pList[0],"Icon"))+ResConfig.iconImg;
			_num[0] = pList[1]-judgeLuckey(pList[0]);
			numLab1.htmlStrByBorder=_num[0];
			clip2.source=ResConfig.iconPath+(StaticIni.getIniVar(pList[2],"Icon"))+ResConfig.iconImg;
			_num[1] = pList[3]-judgeLuckey(pList[2]);
			numLab2.htmlStrByBorder=_num[1];
			clip3.source=ResConfig.iconPath+(StaticIni.getIniVar(pList[4],"Icon"))+ResConfig.iconImg;
			_num[2] = pList[5]-judgeLuckey(pList[4]);
			numLab3.htmlStrByBorder=_num[2];
			clip4.source=ResConfig.iconPath+(StaticIni.getIniVar(pList[6],"Icon"))+ResConfig.iconImg;
			_num[3] = pList[7]-judgeLuckey(pList[6]);
			numLab4.htmlStrByBorder=_num[3];
			clip5.source=ResConfig.iconPath+(StaticIni.getIniVar(pList[8],"Icon"))+ResConfig.iconImg;
			_num[4] = pList[9]-judgeLuckey(pList[8]);
			numLab5.htmlStrByBorder=_num[4];
			_luckyStr[0]= pList[0];
			_luckyStr[1]= pList[2];
			_luckyStr[2]= pList[4];
			_luckyStr[3]= pList[6];
			_luckyStr[4]= pList[8];
		}
		
		/**
		 *如果幸运符有放入就减少一个 
		 * @return 
		 * 
		 */		
		private function judgeLuckey(j:String):int
		{
			var i:int=0;
			var array:Array	=	RefineUI.getInstance()._bindArr;
			for(var k:int;k<array.length;k++)
			{
				if(j==array[k])
				{
					i++;	
				}	
			}
			return i;
			 
		}
		
		/**
		 *根据传过来的string来判断修改幸运符的数量 
		 * @param i
		 * 
		 */		
		public function modifyNum(i:String):void
		{
			for(var j:int;j<_luckyStr.length;j++)
			{
				if(_luckyStr[j]==i)
				{
					_num[j]++;
					modify(j);
				}
			}


	
		}
		/**
		 *修改幸运符的数量 
		 */
		private function modify(i:int):void
		{
			switch(i)
			{
				case 0:
					numLab1.htmlStrByBorder=_num[0];
					break;
				case 1:
					numLab2.htmlStrByBorder=_num[1];
					break;
				case 2:
					numLab3.htmlStrByBorder=_num[2];
					break;
				case 3:
					numLab4.htmlStrByBorder=_num[3];
					break;
				case 4:
					numLab5.htmlStrByBorder=_num[4];
					break;
				default:
					break;
			}
		}
		
		//获取位置
		public function  setPos(pos:int):void
		{
			_pos=pos;
		}
//		//接收购买成功消息
//		public function buySuccess(e:CustomToClientEvent):void
//		{
//			
//			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUTORMMSG_LUCKY_CHARM);
//		}
		
		
	}
}